package edu.sias.userQuestion.service.Impl;

import edu.sias.common.utils.bean.BeanUtils;
import edu.sias.userQuestion.domain.Submit;
import edu.sias.userQuestion.domain.Userques;
import edu.sias.userQuestion.domain.UserquesDto;
import edu.sias.userQuestion.mapper.UserquestionMapper;
import edu.sias.userQuestion.service.UserquestionService;
import edu.sias.userQuestion.utils.Esuq;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpSession;
import java.io.IOException;

@Service
public class UserquestionServiceImpl implements UserquestionService {
    @Autowired
    private UserquestionMapper userquestionMapper;
    @Autowired
    private Esuq esuq;

    //添加
    @Override
    public void add(Userques userQues, HttpSession session) throws IOException {
        UserquesDto userquesDto = new UserquesDto();
        Submit submit = new Submit();
        BeanUtils.copyBeanProp( userquesDto,userQues);
        userquestionMapper.add(userquesDto);
        submit.setId(String.valueOf(userquesDto.getId()));
        submit.setOptions(userQues.getOptions());
        submit.setCorrectAnswers(userQues.getCorrectAnswers());
        esuq.add(submit);
    }
    //查询
    @Override
    public Submit findById(Userques userQues) throws IOException {
        Integer byUserIdAndQuestionId = userquestionMapper.getByUserIdAndQuestionId(userQues);
        Submit submit = esuq.getById(String.valueOf(byUserIdAndQuestionId));

        return  submit;
    }
}
